package haoyc;

import haoyc.handler.ServerInitializer;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;
import java.util.Scanner;

/**
 * @author Memory
 * @version 1.0
 * @date 2021/12/13
 */
@Slf4j
public class Controller {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入目标服务器ip地址:");
        String ip = scanner.next();
        System.out.println("请输入目标服务器端口:");
        Integer port = scanner.nextInt();
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            new Bootstrap()
                    .group(new NioEventLoopGroup())
                    .channel(NioSocketChannel.class)
                    .handler(new ServerInitializer())
                    .connect(new InetSocketAddress(ip, port))
                    .sync();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            group.shutdownGracefully();
        }

    }
}
